package com.example.yrdev.ordering_system.CustomView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.EditText;

import com.example.yrdev.ordering_system.Utils.GlobalFunction;

/**
 * Created by luke on 10/10/16.
 */

public class CustomEditText extends EditText {
   public static  boolean checkPrice=true;

    public interface Callback{
        void dismissedKeyboard();

    }
    Callback callback;

    CustomEditText(Context context){

        super(context);

    }

    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    public CustomEditText(Context context, AttributeSet attrs) {

        super(context, attrs);

    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onKeyPreIme(int keyCode, KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            dispatchKeyEvent(event);
            if (checkPrice){
                Double price=0.;
                if (getText().toString().length()>0)
                    price=Double.valueOf(getText().toString());


                if (price==0){
                    return true;
                }else {
                    return false;

                }
            }


            return true;
        }
        return super.onKeyPreIme(keyCode, event);
    }



}
